Command-line interface implementation for UTCP
The CLI provider enables UTCP to interact with local command-line tools and utilities, allowing AI agents to leverage existing command-line interfaces without requiring API wrappers. This bridges the gap between modern AI agents and traditional command-line utilities.
CLI providers are configured using the following JSON structure:
{ "name": "my_cli_tool", "provider_type": "cli", "command_name": "my-command", "working_dir": "/path/to/data", "param_style": "named", "output_format": "json", "timeout": 30000, "env_vars": { "MY_VAR": "some_value", "DEBUG": "1" } }
Field | Required | Description |
---|---|---|
name |
Yes | Unique identifier for the provider |
provider_type |
Yes | Must be set to "cli" |
command_name |
Yes | Name of the CLI command to execute |
working_dir |
No | The working directory from which to run the command |
param_style |
No | How to pass parameters to the command (default: "named" ) |
output_format |
No | Expected output format (default: "json" ) |
timeout |
No | Command timeout in milliseconds (default: 30000 ) |
env_vars |
No | A dictionary of environment variables to set for the command's execution context |
CLI tools can receive parameters in several ways, specified by the param_style
field:
Style | Description | Example |
---|---|---|
named |
Parameters as named options (--name value) | my-command --input file.txt --format json |
positional |
Parameters as positional arguments | my-command file.txt json |
json |
Parameters as a JSON string in a single argument | my-command '{"input": "file.txt", "format": "json"}' |
json_stdin |
Parameters as JSON sent to the command's standard input | echo '{"input": "file.txt"}' | my-command |
CLI tools can output results in various formats:
Format | Description |
---|---|
json |
Command outputs JSON that can be directly parsed |
text |
Command outputs plain text that needs custom parsing |
csv |
Command outputs CSV data that will be parsed into an array |
xml |
Command outputs XML that will be parsed into a JSON structure |
CLI tools can expose their UTCP tool definitions in two ways:
The CLI tool accepts a special flag (e.g., --utcp-info
) that outputs tool definitions:
$ my-command --utcp-info { "version": "1.0", "tools": [ { "name": "convert", "description": "Convert between file formats", "inputs": { ... }, "outputs": { ... } } ] }
Tool definitions are provided in the provider configuration:
{ "name": "my_cli_tool", "provider_type": "cli", "command_name": "my-command", "tools": [ { "name": "convert", "description": "Convert between file formats", "inputs": { ... }, "outputs": { ... } } ] }
{ "name": "file_converter", "provider_type": "cli", "command_name": "convert", "param_style": "named", "output_format": "json", "timeout": 60000 }
{ "name": "data_processor", "provider_type": "cli", "command_name": "process-data", "param_style": "json_stdin", "output_format": "json", "working_dir": "/path/to/data", "timeout": 120000, "env_vars": { "PYTHONPATH": "/custom/python/path", "DEBUG": "1" } }
{ "name": "system_monitor", "provider_type": "cli", "command_name": "monitor", "param_style": "positional", "output_format": "csv", "timeout": 10000, "env_vars": { "PATH": "/usr/local/bin:/usr/bin:/bin" } }
CLI providers execute commands on the local system, which presents significant security risks if not properly managed. Always implement proper security measures.
© 2024 Universal Tool Calling Protocol. All rights reserved.